<?php
namespace app\admin\controller\user;

use app\admin\model\AdminRole;
use app\admin\service\sys\RoleService;
use app\admin\service\user\UserService;
use app\common\controller\AdminBase;
use app\common\model\UserCate as UserCateModel;

/**
 * 用户操作控制器
 * 列表 添加 修改 删除等
*/
class UserCate extends AdminBase{
    /**
     * 列表
     */
    public function cate_list(){

        $parmas =reqDecode();//获取并参数解密

        $model = new UserCateModel();

        $list = $model->withSearch($this->searchFields($parmas),$this->searchData($parmas))
            ->field('id,name,des,state')
            ->order('id','desc')
            ->paginate($parmas['limit'], false)->toArray();

        return suc('成功',$list);
    }
    /**
     * 添加/编辑用户分组
    */
    public function cate_add(){
       $user = reqDecode();//获取并参数解密

       if(!empty($user['name'])){
           $res = UserService::saveOrEditUserCate($user);
           return $res;
       }
       return suc('非法访问','',1);
    }

    /**
     * 获取用户分组数组信息
     * 用于下拉的源数据
     * id,name
     */
    public function cate_arr(){
        $res = UserCateModel::where('state',1)->order('id','ASC')->column('id,name');
        return suc('成功',$res);
    }
}
